RequestSlaveState
Requests an EtherCAT slave to go into the specified EtherCAT state. For example, if the state is Op, and your requested state is PreOp, the slave will change the state to Op -> SafeOp -> PreOp. If the state is Init and your requested state is Op, the slave will change the state to Init -> PreOp -> SafeOp -> Op.
Syntax
KsCommandStatus RequestSlaveState(
int SlaveId,
EthercatState State
);
Parameters
SlaveId: the index of a slave array. When EtherCAT is started, this index has the same value as the SlaveId, which corresponds to the position of the slave in the network. Please note that after EtherCAT is started in the Operational (Op) state, any addition or removal of slaves from the network will change the position of the slaves in the network (SlaveId). Nevertheless, the index of the slave will remain the same. Newly added devices will be added in the back of the slave array. For all slaves after the change, the index and SlaveId will no longer match. This behavior is only available for physical devices; simulated devices are inapplicable. Please refer to the use cases in EnableHotConnect for more details.
State: the requested EtherCAT state. See the EthercatState type.
Return value
Returns the KsCommandStatus structure.
Remarks
- Both EtherCAT master and slave need to be in one of the supported states.
- It is not possible to request the EtherCAT state that is higher than the master state. For further details about which states the master supports, see RequestState.
Usable EtherCAT states
ecatInit, ecatBoot, ecatPreOP, ecatSafeOP, ecatOP
Example
SlaveStatus sStatus = { 0 };
nRet = GetSlaveById(0, &sStatus);
if (nRet == errNoError)
{
if (sStatus.State != ecatOffline) {
// You can follow the EtherCAT state diagram, or just enter the desired state.
// Switch to Init
WaitForCommand(3, TRUE, RequestSlaveState(0, ecatInit));
// Operate the slave in Init state
// Switch to Bootstrap
WaitForCommand(3, TRUE, RequestSlaveState(0, ecatBoot));
// Operate the slave in Bootstrap state
// Switch back to original state
WaitForCommand(3, TRUE, RequestSlaveState(0, sStatus.State));
}
}
Requirements
RT | Win32 | |
---|---|---|
Minimum supported version | 4.0 | 4.0 |
Header | ksapi.h | ksapi.h |
Library | KsApi_Rtss.lib | KsApi.lib |
See also